package Test;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/4/6
 * \* Time: 16:13
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */


public class Demo9 {
    static class Result{
        public int sum = 0;
        public Object lock = new Object();
    }

    public static void main(String[] args) throws InterruptedException {
        Result result = new Result();
        Thread t = new Thread(){
            @Override
            public void run() {
                int sum = 0;
                for (int i = 0; i <= 1000 ; i++) {
                    sum+=i;
                }
                synchronized (result.lock){
                    result.sum = sum;
                    result.lock.notify();
                }
            }
        };
        t.start();

        synchronized (result.lock){
            while (result.sum == 0){
                result.lock.wait();
            }
            System.out.println(result.sum);
        }
    }
}
